/*     */ package com.wzh.action.control.book;
/*     */ 
/*     */ import com.opensymphony.xwork2.ActionContext;
/*     */ import com.opensymphony.xwork2.ActionSupport;
/*     */ import com.wzh.bean.PageView;
/*     */ import com.wzh.bean.QueryResult;
/*     */ import com.wzh.bean.book.BookInfo;
/*     */ import com.wzh.constant.CommonConstant;
/*     */ import com.wzh.service.bookinfo.BookInfoService;
/*     */ import com.wzh.service.bookinfo.booktype.BookTypeService;
/*     */ import com.wzh.utils.CommonUtil;
/*     */ import java.io.Serializable;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.UUID;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.ServletContext;
/*     */ import org.apache.struts2.ServletActionContext;
/*     */ import org.springframework.stereotype.Controller;
/*     */ 
/*     */ @Controller
/*     */ public class BookManageAction extends ActionSupport
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*     */ 
/*     */   @Resource
/*     */   private BookInfoService bookService;
/*     */ 
/*     */   @Resource
/*     */   private BookTypeService bookTypeService;
/*  31 */   private int page = 1;
/*     */   private String titleorauthor;
/*     */   private BookInfo bookInfo;
/*     */ 
/*     */   public BookInfo getBookInfo()
/*     */   {
/*  37 */     return this.bookInfo;
/*     */   }
/*     */ 
/*     */   public void setBookInfo(BookInfo bookInfo) {
/*  41 */     this.bookInfo = bookInfo;
/*     */   }
/*     */ 
/*     */   public String getTitleorauthor() {
/*  45 */     return this.titleorauthor;
/*     */   }
/*     */ 
/*     */   public void setTitleorauthor(String titleorauthor) {
/*  49 */     this.titleorauthor = titleorauthor;
/*     */   }
/*     */ 
/*     */   public int getPage() {
/*  53 */     return this.page;
/*     */   }
/*     */ 
/*     */   public void setPage(int page) {
/*  57 */     this.page = page;
/*     */   }
/*     */ 
/*     */   public String index()
/*     */   {
/*  64 */     PageView pageView = new PageView(CommonConstant.MAXRESULT, this.page);
/*     */ 
/*  66 */     int firstIndex = (this.page - 1) * CommonConstant.MAXRESULT;
/*     */ 
/*  69 */     String whereStr = "";
/*  70 */     List params = new ArrayList();
/*  71 */     if ((this.titleorauthor != null) && (!"".equals(this.titleorauthor.trim()))) {
/*  72 */       whereStr = " o.title=?1 or o.author=?2 ";
/*     */ 
/*  74 */       params.add(this.titleorauthor.trim());
/*  75 */       params.add(this.titleorauthor.trim());
/*     */     }
/*     */ 
/*  79 */     QueryResult qr = this.bookService.getScrollData(firstIndex, CommonConstant.MAXRESULT, 
/*  80 */       whereStr, params.toArray());
/*  81 */     pageView.setRecords(qr.getResultlist());
/*  82 */     pageView.setTotalrecords((int)qr.getTotalrecord());
/*  83 */     ActionContext.getContext().put("pageView", pageView);
/*  84 */     return "index";
/*     */   }
/*     */   public String edit() {
/*  87 */     this.bookInfo = ((BookInfo)this.bookService.find(this.bookInfo.getId()));
/*  88 */     List bookTypes = this.bookTypeService.getScrollData().getResultlist();
/*     */ 
/*  90 */     ActionContext.getContext().put("bookTypes", bookTypes);
/*  91 */     return "edit";
/*     */   }
/*     */ 
/*     */   public String update() {
/*  95 */     BookInfo oldBook = (BookInfo)this.bookService.find(this.bookInfo.getId());
/*  96 */     oldBook.setTitle(this.bookInfo.getTitle());
/*  97 */     oldBook.setAuthor(this.bookInfo.getAuthor());
/*  98 */     oldBook.setIsfinish(this.bookInfo.isIsfinish());
/*  99 */     oldBook.setIntro(this.bookInfo.getIntro());
/* 100 */     oldBook.setStars(this.bookInfo.getStars());
/* 101 */     oldBook.setHit(this.bookInfo.getHit());
/* 102 */     oldBook.setBooktype(this.bookInfo.getBooktype());
/*     */ 
/* 104 */     this.bookService.update(oldBook);
/* 105 */     ActionContext.getContext().put("message", "修改成功");
/* 106 */     ActionContext.getContext().put("urladdress", "/control/book/index");
/* 107 */     return "message";
/*     */   }
/*     */   public String delete() {
/* 110 */     this.bookService.delete(new Serializable[] { this.bookInfo.getId() });
/* 111 */     ActionContext.getContext().put("message", "删除成功");
/* 112 */     ActionContext.getContext().put("urladdress", "/control/book/index");
/* 113 */     return "message";
/*     */   }
/*     */ 
/*     */   public String downLoadImg()
/*     */   {
/* 118 */     String whereStr = " o.imgdowned=?1 ";
/* 119 */     List params = new ArrayList();
/* 120 */     params.add(Boolean.valueOf(false));
/*     */ 
/* 123 */     int maxresult = 3;
/* 124 */     int firstindex = (this.page - 1) * maxresult;
/* 125 */     List<BookInfo> books = this.bookService.getScrollData(firstindex, maxresult, whereStr, params.toArray()).getResultlist();
/*     */ 
/* 128 */     if ((books == null) || (books.size() == 0)) {
/* 129 */       ActionContext.getContext().put("urladdress", "/control/book/index");
/* 130 */       ActionContext.getContext().put("message", "所有图片下载成功");
/* 131 */       return "automessage";
/*     */     }
/* 133 */     StringBuilder message = new StringBuilder();
/* 134 */     for (BookInfo book : books) {
/* 135 */       String imageurl = book.getImageurl();
/* 136 */       String imageSaveName = "/files/img/" + book.getBooktype() + "/" + UUID.randomUUID() + getExt(imageurl);
/* 137 */       String realPath = ServletActionContext.getServletContext().getRealPath(imageSaveName);
/*     */ 
/* 139 */       if (imageurl.startsWith("http://")) {
/* 140 */         if (CommonUtil.downLoadImg(book.getImageurl(), realPath)) {
/* 141 */           message.append(book.getImageurl() + "下载成功\n");
/* 142 */           book.setImageurl(imageSaveName);
/*     */         }
/*     */         else
/*     */         {
/* 146 */           message.append(book.getImageurl() + "下载失败\n");
/* 147 */           book.setImageurl("");
/*     */         }
/* 149 */         book.setImgdowned(true);
/* 150 */         this.bookService.update(book);
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 156 */     message.append("3秒后下载一下组图片");
/* 157 */     ActionContext.getContext().put("urladdress", "/control/book/downimg");
/* 158 */     ActionContext.getContext().put("message", message.toString());
/* 159 */     return "automessage";
/*     */   }
/*     */ 
/*     */   private String getExt(String filepath)
/*     */   {
/* 164 */     if ((filepath == null) || ("".equals(filepath))) {
/* 165 */       return ".jpg";
/*     */     }
/*     */ 
/* 168 */     String ext = filepath.substring(filepath.lastIndexOf("."), filepath.length());
/* 169 */     return ext;
/*     */   }
/*     */ 
/*     */   public String geneTxts()
/*     */   {
/* 177 */     List bookInfos = (List)ActionContext.getContext().getSession().get("genetxtBookInfo");
/*     */ 
/* 181 */     if ((bookInfos == null) || (bookInfos.size() == 0))
/*     */     {
/* 183 */       Integer genetxtpage = (Integer)ActionContext.getContext().getSession().get("genetxtpage");
/*     */ 
/* 185 */       if (genetxtpage == null) {
/* 186 */         genetxtpage = Integer.valueOf(0);
/*     */       }
/* 188 */       genetxtpage = Integer.valueOf(genetxtpage.intValue() + 1);
/* 189 */       int firstIndex = (genetxtpage.intValue() - 1) * 3;
/* 190 */       bookInfos = this.bookService.getScrollData(firstIndex, 3).getResultlist();
/*     */ 
/* 192 */       if ((bookInfos == null) || (bookInfos.size() == 0)) {
/* 193 */         ActionContext.getContext().put("message", "恭喜，所有小说zip生成完毕");
/* 194 */         ActionContext.getContext().put("urladdress", "/control/book/index");
/*     */       } else {
/* 196 */         ActionContext.getContext().getSession().put("genetxtpage", genetxtpage);
/* 197 */         ActionContext.getContext().getSession().put("genetxtBookInfo", bookInfos);
/* 198 */         ActionContext.getContext().put("message", "3秒后开始批量生成小说zip文件");
/* 199 */         ActionContext.getContext().put("urladdress", "/control/book/genetxts");
/*     */       }
/*     */     }
/*     */     else {
/* 203 */       BookInfo book = (BookInfo)bookInfos.get(0);
/*     */ 
/* 205 */       this.bookService.geneTxt(book);
/*     */ 
/* 207 */       bookInfos.remove(0);
/* 208 */       ActionContext.getContext().put("message", "生成" + book.getTitle() + ".zip成功,3秒后生成下一部小说zip");
/* 209 */       ActionContext.getContext().put("urladdress", "/control/book/genetxts");
/*     */     }
/* 211 */     return "automessage";
/*     */   }
/*     */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.action.control.book.BookManageAction
 * JD-Core Version:    0.6.1
 */